/*user to person table*/

$N.databaseSet.UserToPersonTable = (function ($N) {
    function init() {
    	var tableName = "UserToPerson";
    	var fields = new Array("ID integer,\
                                personID varchar(15),\
                                userName varchar(30), \
                                retitle varchar(10), \
                                modified datetime");
    	function createUserToPersonTableCb() {
    		console.log("UserToPersonTable creates successfully.");
    	}
    	$N.databaseSet.createNormalTable(tableName, fields, createUserToPersonTableCb);
    }
    
	function getUserToPersonData(userName, cb, errorCb) {
		var sqlCommand = "SELECT personID FROM UserToPerson WHERE userName = ?";
		$N.databaseSet.executeSQL($N.databaseSet.db, sqlCommand, [userName], cb, errorCb);
	}

	function addUserToPersonData(data, cb, errorCb) {
		var sqlCommand = "INSERT INTO UserToPerson (ID, personID, userName, retitle, modified) values(?, ?, ?, ?, ?)";
		var sqlValueArray = new Array(parseInt(data.id), data.personID, data.username, data.retitle, data.modified);
		$N.databaseSet.executeSQL($N.databaseSet.db, sqlCommand, sqlValueArray, cb, errorCb);
	}

	function updateUserToPersonData(data, cb, errorCb) {
		console.log("Reserved : updateUserToPersonData");
	}

	return {
        init                : init,
		getUserToPersonData : getUserToPersonData,
		addUserToPersonData : addUserToPersonData
	};
}($N || {}));